package q318_maxProduct;

public class Solution_2 {
    /*
    相较于solution1
    我们事先用一个数组将每个单词的位运算存储下来 这样就能够减少循环中判断的次数
     */
    public int maxProduct(String[] words) {
        int maxX = 0;
        int[] bits = new int[words.length];
        for (int i = 0; i < words.length; i++) {
            int bit = 0;
            for (Character character : words[i].toCharArray()) bit |= (1 << (character - 'a'));
            bits[i] = bit;
        }
        for (int i = 0; i < words.length; i++) {
            for (int j = i; j < words.length; j++) {
                if ((bits[i] & bits[j]) == 0) maxX = Math.max(words[i].length() * words[j].length(), maxX);
            }
        }

        return maxX;
    }

}
